package Concurrency2.Chapter01_Base;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static utils.MUtils.print;
import static utils.MUtils.timeDelay;


/**
 * Instruction：测试内容
 * 1, 线程池的任务提交是异步的;
 * 2, execute提交的任务不强制处理异常
 * Author：@author MaLi
 */
public class T08_ThreadPool {
    //测试线程池的两种任务提交方式
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(1);
        pool.execute(() -> {
            for (int i = 0; i < 100; i++) {
//                System.out.println("i-->" + i);
                print("hello pool --> " + i);
                if (i == 5) {
                    int result = 1 / 0;
                }
                timeDelay(1);
            }
        });
        System.out.println("提交完任务的过程是异步执行吗"); //肯定是异步执行
        //当前线程池只接收一个任务, 其它的任务, 缓存在无界队列中.
        pool.execute(() -> {
            for (int i = 0; i < 100; i++) {
//                System.out.println("hello pool --> " + i);
                print("hello pool --> " + i);
                timeDelay(1);
            }
        });
    }


}
